#if FacebookSDK
using Facebook.Unity;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

public class FacebookSDK : MonoBehaviour
{
    static FacebookSDK _instance;
    public static FacebookSDK instance => _instance;
    private void Awake()
    {
        _instance = this;

        DontDestroyOnLoad(gameObject);
    }

    // Start is called before the first frame update
    void Start()
    {
            
        if (FB.IsInitialized)
        {
            Debug.Log("FB  IsInitialized");
            FB.ActivateApp();
        }
        else
        {
            Debug.Log("FB  Init");
            FB.Init(() => 
            {
                Debug.Log("FB  ActivateApp");
                FB.ActivateApp();
            });
        }
    }

    /**
 * Include the Facebook namespace via the following code:
 * using Facebook.Unity;
 *
 * For more details, please take a look at:
 * developers.facebook.com/docs/unity/reference/current/FB.LogAppEvent
 */
    public void LogAchieveLevelEvent(string level)
    {
        var parameters = new Dictionary<string, object>();
        parameters[AppEventParameterName.Level] = level;
        FB.LogAppEvent(
            AppEventName.AchievedLevel, 0,
            parameters
        );
    }

    // from the background
    void OnApplicationPause(bool pauseStatus)
    {
        // Check the pauseStatus to see if we are in the foreground
        // or background
        if (!pauseStatus)
        {
            //app resume
            if (FB.IsInitialized)
            {
                FB.ActivateApp();
            }
            else
            {
                //Handle FB.Init
                FB.Init(() => {
                    FB.ActivateApp();
                });
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        
    }
}
#endif